package com.sicheng.lc.杂题.前缀和之异或篇;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/7/13 15:15
 */
public class 子数组异或查询 {
    //https://leetcode.cn/problems/xor-queries-of-a-subarray/
    public int[] xorQueries(int[] arr, int[][] queries) {
        int[] sum = new int[arr.length + 1];

        for (int i = 1; i <= arr.length; i++) {
            sum[i] = sum[i - 1] ^ arr[i - 1];
        }

        int[] res = new int[queries.length];
        for (int i = 0; i < queries.length; i++) {
            res[i] = sum[queries[i][0] + 1] ^ sum[queries[i][1]];
        }
        return res;
    }
}
